﻿using Shop.RemoteModel.Activity;
using Shop.RemoteModel.Activity.Model;
using Shop.StoreGatewayModular.Interface;
using Shop.StoreGatewayModular.Model.Activity;
using WeDonekRpc.Client;
using WeDonekRpc.HttpApiGateway.Model;

namespace Shop.StoreGatewayModular.Service
{
    internal class ActivityService : IActivityService
    {
        public long Add ( ActivityAdd data )
        {
            return new AddActivity
            {
                Datum = data
            }.Send();
        }
        public void Delete ( long id )
        {
            new DeleteActivity
            {
                Id = id
            }.Send();
        }
        public ActivityDetailedDto GetDetailed ( long id )
        {
            ActivityDetailed dto = new GetActivityDetailed
            {
                ActivityId = id
            }.Send();
            ActivityDetailedDto t = dto.ConvertMap<ActivityDetailed, ActivityDetailedDto>();
            t.RangeName = t.Range.ToString();
            t.UserRangeName = t.UserRange.ToString();
            return t;
        }
        public bool OffShelf ( long id )
        {
            return new ActivityOffShelf
            {
                Id = id
            }.Send();
        }
        public ActivityData Get ( long id )
        {
            return new GetActivity
            {
                Id = id
            }.Send();
        }
        public bool Set ( long id, ActivitySet set )
        {
            return new SetActivity
            {
                Id = id,
                Datum = set
            }.Send();
        }
        public PagingResult<ActivityBase> Query ( PagingParam<ActivityQueryParam> query )
        {
            return new QueryActivity
            {
                Index = query.Index,
                IsDesc = query.IsDesc,
                Size = query.Size,
                SortName = query.SortName,
                NextId = query.NextId,
                Query = query.Query
            }.Send();
        }
        public void SubmitAudit ( long id )
        {
            _ = new SubmitActivityAudit
            {
                ActivityId = id
            }.Send();
        }

        public bool AuditPass ( long id, long empId )
        {
            return new SubmitActivityAuditResult
            {
                Id = id,
                Result = new AuditResult
                {
                    EmpId = empId,
                    IsPass = true
                }
            }.Send();
        }

        public bool AuditNoPass ( long id, long empId, string opinion )
        {
            return new SubmitActivityAuditResult
            {
                Id = id,
                Result = new AuditResult
                {
                    EmpId = empId,
                    IsPass = false,
                    Opinion = opinion
                }
            }.Send();
        }

        public ActivityBase[] Gets ( long[] ids )
        {
            return new GetActivitys
            {
                Ids = ids
            }.Send();
        }
    }
}
